<%-- 
    Document   : dvdDetails
    Created on : Dec 2, 2011, 8:15:37 PM
    Author     : rkoretke
--%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@ page import="com.cheapflix.beans.UserDVD" %>
<%@ page import="com.cheapflix.beans.User" %>
<%@ page import="com.cheapflix.beans.DVD" %>
<%@ page import="com.cheapflix.beans.RecommendedDVD" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/views/includes.jsp" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Flix Details</title>
        <link rel="stylesheet" type="text/css" href="/cheapflix/css/style.css" />
        <script type="text/javascript" src="<c:url value="/js/login.js"/>"/>
        <script>
         
        </script>
    </head>
    <body>
        <div class="outer">
            <%@ include file="/WEB-INF/views/header.jsp" %>
            <div class="row rowstyle rowleft">

                <div class="searchResults">
                    <h1><c:out value="${dvd.title}"/></h1>
                    <c:choose>
                        <c:when test="${ udvd.rating==0}">
                            <div class="searchResults" style="width:300px;">
                                <div class="message" style="margin-bottom:5px;">You have not rated this movie</div><br/>

                                <form action="/cheapflix/rate" >
                                    <input type="hidden" name="dvdid" value="<c:out value="${dvd.id}"/>"/>
                                    <label style="float:left;width:100px;">Comment:</label><input type="text" name="comment"><br/>
                                    <label style="float:left;width:100px;">Rating:</label>
                                    <select name="rating">
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                        <option value="4">4</option>
                                        <option value="5">5</option>
                                    </select><br/>

                                    <input type="submit" value="Rate Flick"/>
                                </form>
                            </div>
                        </c:when>
                        <c:when test="${udvd== null }">
                            <div style="margin-top:10px;margin-bottom:10px;width:300px"><a href="/cheapflix/rate?dvdid=<c:out value="${dvd.id}&rating=0&comment="/>">Add Movie to Queue</a></div>
                        </c:when>
                        <c:when test="${udvd != null}">

                            <span class="message" style="margin-bottom:5px;" >Your rating:</span>
                            <%
                                UserDVD udvd = (UserDVD) request.getAttribute("udvd");
                                for (int x = 0; x < udvd.getRating(); x++) {
                            %>
                            <img width="20" height="20" src="<c:url value="/images/star.png"/>"/>
                            <%                                        }
                            %>
                            <br/>
                            <span class="message"  style="margin-bottom:5px;">Your Comment:</span><c:out value="${udvd.comment}"/><br/>
                        </c:when>
                    </c:choose>
                    <c:choose>
                        <c:when test="${avgRating != -1}">
                            <span class="message" style="margin-bottom:5px;">Average Rating:</span>
                            <%
                                double avgRating = (Double) request.getAttribute("avgRating");
                                double flooredAvgRating = Math.floor(avgRating);
                                for (int x = 0; x < flooredAvgRating; x++) {
                            %>
                            <img width="20" height="20" src="<c:url value="/images/star.png"/>"/>
                            <%                                }
                                if (avgRating % 1.0 > 0) {
                            %>
                            <img width="20" height="20" src="<c:url value="/images/star_half.png"/>"/>
                            <%                                    }
                            %>
                            (<c:out value="${avgRating}"/>)<br/>
                        </c:when>
                    </c:choose>
                    <table >
                        <tr>
                            <td>
                                <img src="${dvd.image}" alt="">
                            </td>
                            <c:if test="${fn:length(me.friends) > 0}">
                                <td valign="top">
                                    <div class="message">Recommend this DVD to your friends</div>
                                    <form action="/cheapflix/recommend" method="GET" onsubmit="return checkRecommendTable();">
                                        <input type="hidden" name="dvdid" value="<c:out value="${dvd.id}"/>"/>
                                        <table style="overflow: scroll;" id="recommendTable">
                                            <tr>
                                                <%
                                                    User me = (User) session.getAttribute("me");
                                                    Map< String, User> friends = me.getFriends();
                                                    for (String fu : friends.keySet()) {

                                                        User thisFriend = friends.get(fu);
                                                        pageContext.setAttribute("friend", thisFriend);
                                                %>
                                            <tr>
                                                <td>
                                                    <%

                                                        DVD thisDVD = (DVD) request.getAttribute("dvd");
                                                        if (me.getDidRecommend(thisDVD.getId(), thisFriend.getId())) {
                                                    %>
                                                    <img src="<c:url value="/images/accepted.png"/>"/>
                                                    <%} else {%>
                                                    <input type="checkbox" name="<c:out value="${friend.id}"/>"/>
                                                    <input type="hidden" name="param" value="<c:out value="${friend.id}"/>"/>
                                                    <%}%>
                                                </td>
                                                <td><a href="/cheapflix/users/<c:out value="${friend.id}"/>"><c:out value="${friend.nameFirst}"/> <c:out value="${friend.nameLast}"/></a></td></tr>
                                                <%}%>
                                            </tr>
                                        </table>
                                        <input type="submit" value="Recommend" />
                                    </form>
                                </td>
                            </c:if>
                        </tr>
                    </table>
                    <br>
                    <span class="srLabel srLabel2"><b>Starring: </b></span><c:out value="${dvd.actors}"/><br>
                    <span class="srLabel srLabel2"><b>Directed By: </b></span><c:out value="${dvd.director}"/><br>
                    <span class="srLabel srLabel2"><b>Genre: </b></span><c:out value="${dvd.genre}"/><br>
                    <span class="srLabel srLabel2"><b>Year: </b></span><c:out value="${dvd.year}"/><br>
                    <span class="srLabel srLabel2"><b>Runtime: </b></span><c:out value="${dvd.runtime}"/><br>
                </div>
            </div>
            <%@ include file="/WEB-INF/views/footer.jsp" %>
        </div>
    </body>
</html>
